package xycdao

import (
	"Cgo/front/models"
	"Cgo/global"
)

type xycShopDao struct{}

var XycShopDao = xycShopDao{}

// 根据id查询商品,不传id则查询所有商品
func (xycShopDao) FindShopByIdDao(id int) ([]models.XycShop, error) {
	var shopList []models.XycShop

	if r := global.DB.Where(models.XycShop{Id: id}).Find(&shopList); r.Error != nil {
		return shopList, r.Error
	} else {
		return shopList, nil
	}
}

// 根据状态返回商品列表
func (xycShopDao) FindShopByStatusDao(status string) ([]models.XycShop, error) {
	var shopList []models.XycShop

	if r := global.DB.Where(models.XycShop{Status: status}).Find(&shopList); r.Error != nil {
		return shopList, r.Error
	} else {
		return shopList, nil
	}
}

// 根据分类查询商品列表
func (xycShopDao) FindShopByClassifyDao(classify string) ([]models.XycShop, error) {
	var shopList []models.XycShop

	if r := global.DB.Where(models.XycShop{Classify: classify}).Find(&shopList); r.Error != nil {
		return shopList, r.Error
	} else {
		return shopList, nil
	}
}

// 根据商品名字模糊查询商品列表
func (xycShopDao) FindShopByNameDao(name string) ([]models.XycShop, error) {
	var shopList []models.XycShop

	if r := global.DB.Where("name like ?", "%"+name+"%").Find(&shopList); r.Error != nil {
		return shopList, r.Error
	} else {
		return shopList, nil
	}
}
